use lazy_static::lazy::Lazy;
use lazy_static::lazy_static;
use std::fmt::Debug;
use std::marker::PhantomPinned;
use std::mem;
use std::mem::ManuallyDrop;
use std::ops::DerefMut;
use std::pin::Pin;
use std::ptr::NonNull;
use std::sync::{Arc, Mutex};
use crossbeam::epoch::pin;
use tokio::pin;

pub mod executor;
pub mod time_future;

#[test]
fn test1() {
    let arc = Arc::new(1);
    let null = std::ptr::NonNull::<i32>::dangling();
    let null2 = std::ptr::NonNull::<f32>::dangling();
    let null1 = std::ptr::null::<i32>();
    unsafe {
        let null3 = NonNull::new_unchecked(null1 as *mut i32);
        println!("{:?}", null.as_ptr());
        println!("{:?}", null2.as_ptr());
        println!("{:?}", null1);
        println!("{:?}", null3.as_ptr());
        *null3.as_ptr() = 1;
    }
}
#[derive(Debug)]
struct UnMovable {
    data: String,
    slice: *const String,
    // _pin: PhantomPinned,
}

impl UnMovable {
    fn new(value: String) -> Self {
        UnMovable {
            data: value,
            slice: std::ptr::null(),
            // _pin: PhantomPinned,
        }
    }

    fn init(self: Pin<&mut Self>) {
        unsafe {
            self.get_unchecked_mut().slice = &self.data;
        }
    }
}

#[test]
fn test2() {
    lazy_static! {
        static ref STR_PIN: String = "test".to_string();
    }
    // let unmove = UnMovable {
    //     data: STR_PIN.clone(),
    //     slice: NonNull::dangling(),
    //     // _pin: PhantomPinned,
    // };
    // let mut pin_unmove = Box::pin(unmove);
    // let slice = NonNull::from(&pin_unmove.data);
    // unsafe {
    //     pin_unmove.as_mut().get_unchecked_mut().slice = slice;
    // }
    //
    // println!("{:#?}", pin_unmove);
    //
    // // let x = Box::new(1);
    // // let leak1 = Box::leak(x);
    // // let man_frop = ManuallyDrop::new(Box::new(1));
    // // unsafe {
    // //     &mut *ManuallyDrop::new(Box::new(2)).0.as_ptr();
    // // }

    let mut movable1 = UnMovable::new("1".to_string());
    let mut movable2 = UnMovable::new("2".to_string());
    pin!(movable1);
    pin!(movable2);
    // let mut movable11 = unsafe { Pin::new_unchecked(&mut movable1) };
    // let mut movable22 = unsafe { Pin::new_unchecked(&mut movable2) };


    // movable1.as_mut().init();
    // movable2.as_mut().init();
    println!("{:?},data_address: {:p}", movable1, &movable1.data);
    // println!("{:?},data_address: {:p}", movable22, &movable22.data);
    // std::mem::swap(&mut movable1, &mut movable2);
    // println!("{:?},data_address: {:p}", movable1, &movable1.data);
    // println!("{:?},data_address: {:p}", movable2, &movable2.data);
    //
    // let mut unsafe_move1 = UnMovable::new("1".to_string());
    // unsafe_move1.slice = &unsafe_move1.data;
    // let mut unsafe_move2 = UnMovable::new("2".to_string());
    // unsafe_move2.slice = &unsafe_move2.data;
    // println!("{:?},data_address: {:p}", unsafe_move1, &unsafe_move1.data);
    // println!("{:?},data_address: {:p}", unsafe_move2, &unsafe_move2.data);
    // std::mem::swap(&mut unsafe_move1, &mut unsafe_move2);
    // println!("{:?},data_address: {:p}", unsafe_move1, &unsafe_move1.data);
    // println!("{:?},data_address: {:p}", unsafe_move2, &unsafe_move2.data);
}
